var app = getApp();
Page(Object.assign({},{
    data:{
        isIPX : app.globalData.isIPX,
        desc : '',
        pic : [],
        inited : false,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
    },
    onShow: function () {
        wx.hideTabBar();
    },
    onLoad:function(options){
        var self = this;

        self.data.options = options;
        var postdata = {
            op : 'sharedesc',
            id : options.id,
        };
        app.com.http('good_v1','POST',postdata,0,false,'','',function(res){
            if (!res.data.errno && res.data) {
                self.setData({
                    desc : res.data.data.desc,
                    pic : res.data.data.pic,
                    params : res.data.data.params,
                    inited : true,
                })
            }else{
                app.com.toast( res.data.message );
            }
        });
       
        wx.setNavigationBarTitle({
            title:  '分享素材',
        });
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;
        this.onLoad( this.data.options );
        this.setData({
            isdown : false,
        });
        wx.stopPullDownRefresh();
    },
    copy(){
        wx.setClipboardData({
            data : this.data.desc,
            success : function(){}
        });
    },
    saveposter(){
        var self = this;
        var suc = 0;
        for (var i = 0; i < self.data.pic.length; i++) {
            wx.downloadFile({
                url: self.data.pic[i],
                success: function (res) {
                    wx.saveImageToPhotosAlbum({
                        filePath: res.tempFilePath,
                        success(res) {
                            app.com.toast('保存成功');
                        },
                        fail(res) {
                            app.com.toast('保存失败');
                        }
                    })
                },
                fail: function (res) {
                    app.com.toast('下载文件失败'); 
                }
            })
        }
    },
    prev(e){
        var self = this;
        var url = e.currentTarget.dataset.img;
        wx.previewImage({
            current : url,
            urls: self.data.pic
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
            url: url
        })
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },

}))